home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / game / shoot / athrust.lha / AmigaThrust / src / amiga.c next >
Encoding:
C/C++ Source or Header  |  1998-09-05  |  5.9 KB  |  276 lines

  1. /*
  2.  * amiga.c
  3.  * Amiga specific graphic routines for Thrust.
  4.  * Written by Frank Wille, frank@phoenix.owl.de
  5.  *
  6.  */
  7.  
  8. #ifdef HAVE_CONFIG_H
  9. # include "config.h"
  10. #endif
  11.  
  12. #if defined(HAVE_GETOPT_H) && defined(HAVE_GETOPT_LONG_ONLY)
  13. # include <getopt.h>
  14. #elif !defined(HAVE_GETOPT_LONG_ONLY)
  15. # include "getopt.h"
  16. #endif
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21.  
  22. #include <exec/types.h>
  23. #include <exec/libraries.h>
  24. #include <intuition/intuition.h>
  25. #include <rtgmaster/rtgmaster.h>
  26. #include <rtgmaster/rtgsublibs.h>
  27. #include <proto/exec.h>
  28. #include <proto/rtgmaster.h>
  29.  
  30. #include "thrust.h"
  31. #include "fast_gr.h"
  32. #include "gr_drv.h"
  33. #include "options.h"
  34.  
  35. struct Library *GfxBase = NULL;
  36. struct RTGMasterBase *RTGMasterBase = NULL;
  37. struct RtgScreen *RtgScreen = NULL;
  38. static unsigned char *fb;  /* frame buffer of gfx board */
  39. unsigned char *gfxbuf = NULL;  /* gfx buffer - same dimensions as fb */
  40. unsigned char **ytab = NULL;   /* y buffer addresses */
  41. static ULONG rtgwidth,rtgheight,fbwidth,totalsize;
  42.  
  43.  
  44. void clearscr(void)
  45. {
  46.   memset(gfxbuf,0,totalsize);
  47. }
  48.  
  49.  
  50. #ifndef __VBCC__ /* inlined */
  51. void putarea(unsigned char *source, int x, int y, int width, int height,
  52.              int bytesperline, int destx, int desty)
  53. {
  54.   int ix;
  55.   unsigned char *s = source+(y*bytesperline)+x;
  56. #ifdef __PPC__
  57.   unsigned char *d = gfxbuf+(desty*rtgwidth)+destx;
  58. #else
  59.   unsigned char *d = *(ytab+desty)+destx;
  60. #endif
  61.   int smod = bytesperline - width;
  62.   int dmod = rtgwidth - width;
  63.  
  64.   for (; height>0; height--,s+=smod,d+=dmod)
  65.     for (ix=0; ix<width; ix++,*d++=*s++);
  66. }
  67. #endif
  68.  
  69.  
  70. #ifndef __VBCC__ /* inlined */
  71. void putpixel(int x, int y, unsigned char color)
  72. {
  73. #ifdef __PPC__
  74.   *(gfxbuf+(y*rtgwidth)+x) = color;
  75. #else
  76.   *(*(ytab+y)+x) = color;
  77. #endif
  78. }
  79. #endif
  80.  
  81.  
  82. void syncscreen(void)
  83. {
  84. #if 0
  85. /* @@@ does't work on CV64 anyway... */
  86. /* @@@ better sync with WaitTOF to provide the same speed for all ports */
  87. #ifdef WOS
  88.   PPCRtgWaitTOF(RtgScreen);
  89. #else
  90.   RtgWaitTOF(RtgScreen);
  91. #endif
  92.  
  93. #else
  94.   WaitTOF();  /* @@@ */
  95. #endif
  96. }
  97.  
  98.  
  99. void displayscreen(void)
  100. {
  101. #ifdef WOS
  102.   PPCCopyRtgBlit(RtgScreen,fb,gfxbuf,0,0,0,fbwidth,rtgheight,
  103.                  rtgwidth,rtgheight,0,0);
  104. #else
  105.   CopyRtgBlit(RtgScreen,fb,gfxbuf,0,0,0,fbwidth,rtgheight,
  106.               rtgwidth,rtgheight,0,0);
  107. #endif
  108. }
  109.  
  110.  
  111. void fadepalette(int first, int last, unsigned char *RGBtable, int fade, int flag)
  112. {
  113.   static ULONG tmprgb[3*256+2];
  114.   ULONG *p = tmprgb;
  115.   ULONG cnt = (ULONG)(last-first)+1;
  116.   unsigned char *rgb = RGBtable;
  117.   ULONG c;
  118.  
  119.   *p++ = (cnt<<16) | (ULONG)first;
  120.   cnt *= 3;
  121.   while (cnt--) {
  122.     c = ((((ULONG)*rgb++) * (ULONG)(fade<<2)) >> 8) & 0xff;
  123.     *p++ = (c<<24)|(c<<16)|(c<<8)|c;
  124.   }
  125.   *p = 0;
  126.   if(flag)
  127. #ifdef WOS
  128.     PPCRtgWaitTOF(RtgScreen);
  129. #else
  130.     RtgWaitTOF(RtgScreen);
  131. #endif
  132.   LoadRGBRtg(RtgScreen,tmprgb);
  133.   displayscreen();
  134. }
  135.  
  136.  
  137. void fade_in(void)
  138. {
  139.   int i;
  140.  
  141.   for(i=0; i<=64; i+=4)
  142.     fadepalette(0, 255, bin_colors, i, 1);
  143. }
  144.  
  145.  
  146. void fade_out(void)
  147. {
  148.   int i;
  149.  
  150.   for(i=64; i; i-=4)
  151.     fadepalette(0, 255, bin_colors, i, 1);
  152.   clearscr();
  153.   displayscreen();
  154.   usleep(200000L);
  155. }
  156.  
  157.  
  158. void graphics_preinit(void)
  159. {
  160. }
  161.  
  162.  
  163. int graphicsinit(int argc, char **argv)
  164. {
  165.   static struct TagItem sreqtag[] = {
  166.     smr_MinWidth,320,
  167.     smr_MinHeight,200,
  168.     smr_MaxWidth,320,
  169.     smr_MaxHeight,256,
  170.     smr_ProgramUsesC2P,TRUE,
  171.     smr_Buffers,1,
  172.     smr_ChunkySupport,LUT8,
  173.     smr_PlanarSupport,Planar8,
  174.     smr_Workbench,0,  /* @@@ WB-support gets wrong colors, deactivated */
  175.     smr_PrefsFileName,(ULONG)"Thrust.prefs",
  176.     TAG_DONE
  177.   };
  178.   static struct TagItem scrtag[] = {
  179.     rtg_Buffers,1,
  180.     rtg_Workbench,0,
  181. /*    rtg_ChangeColors,1, @@@ try this for WB support? */
  182.     TAG_DONE
  183.   };
  184.   static struct TagItem gtag[] = {
  185.     grd_BytesPerRow,0,
  186.     grd_Width,0,
  187.     grd_Height,0,
  188.     grd_Depth,0,
  189.     grd_PixelLayout,0,
  190.     TAG_DONE
  191.   };
  192.   struct ScreenReq *sr;
  193.   unsigned char *p;
  194.   ULONG i;
  195.  
  196.   if (!(GfxBase = OpenLibrary("graphics.library",36))) {
  197.     printf("Can't open graphics.library V36!\n");
  198.     return (0);
  199.   }
  200.   if (RTGMasterBase = (struct RTGMasterBase *)
  201.       OpenLibrary("rtgmaster.library",27)) {
  202. #if 0
  203.     if (sr = RtgBestSR(sreqtag)) {
  204. #else
  205.     if (sr = RtgScreenModeReq(sreqtag)) {
  206. #endif
  207.       scrtag[1].ti_Data = (sr->Flags&sq_WORKBENCH) ? LUT8 : 0;
  208.  
  209.       if (RtgScreen = OpenRtgScreen(sr,scrtag)) {
  210.         GetRtgScreenData(RtgScreen, gtag);
  211.         rtgwidth = gtag[1].ti_Data;
  212.         rtgheight = gtag[2].ti_Data;
  213.         fbwidth = gtag[0].ti_Data;
  214.         if (gtag[4].ti_Data == grd_PLANAR)
  215.           fbwidth <<= 3;  /* 1 byte per row = 8 pixels in planar mode */
  216.         if (gfxbuf = malloc(totalsize = rtgheight*rtgwidth)) {
  217.           if (ytab = malloc(rtgheight*sizeof(unsigned char *))) {
  218.             /* init offset table */
  219.             for (i=0,p=gfxbuf; i<rtgheight; i++,p+=rtgwidth)
  220.               ytab[i] = p;
  221.             LockRtgScreen(RtgScreen);
  222.             fb = (unsigned char *)GetBufAdr(RtgScreen,0);
  223.             fadepalette(0, 255, bin_colors, 1, 0);
  224.             return (0);
  225.           }
  226.           else
  227.             printf("Can't allocate y offset table!\n");
  228.           free(gfxbuf);
  229.           gfxbuf = NULL;
  230.         }
  231.         else
  232.           printf("Can't allocate gfx buffer!\n");
  233.         CloseRtgScreen(RtgScreen);
  234.         RtgScreen = NULL;
  235.       }
  236.       else
  237.         printf("Can't open screen!\n");
  238.     }
  239.     else
  240.       printf("Gfx resolution with at least 320x200 and 1 byte per pixel "
  241.              "is not available.\n");
  242.     CloseLibrary((struct Library *)RTGMasterBase);
  243.     RTGMasterBase = NULL;
  244.   }
  245.   else
  246.     printf("Can't open rtgmaster.library V27.\n");
  247.   return (-1);
  248. }
  249.  
  250.  
  251. int graphicsclose(void)
  252. {
  253.   if (RTGMasterBase) {
  254.     if (RtgScreen) {
  255.       if (ytab)
  256.         free(ytab);
  257.       if (gfxbuf)
  258.         free(gfxbuf);
  259.       UnlockRtgScreen(RtgScreen);
  260.       CloseRtgScreen(RtgScreen);
  261.     }
  262.     CloseLibrary((struct Library *)RTGMasterBase);
  263.   }
  264.   if (GfxBase)
  265.     CloseLibrary(GfxBase);
  266.   return (0);
  267. }
  268.  
  269.  
  270. char *graphicsname(void)
  271. {
  272.   static char name[] = "RTGMaster";
  273.  
  274.   return name;
  275. }
  276.